package com.njtech.pet.service.impl;


import com.njtech.pet.dao.BillDao;
import com.njtech.pet.entity.Bill;
import com.njtech.pet.entity.Item;
import com.njtech.pet.entity.User;
import com.njtech.pet.service.BillService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
public class BillServiceImpl implements BillService{
    @Autowired
    BillDao billDao;
    /**
     * 插入
     *
     * @param bill 新的记录
     * @return 修改行数
     */
    @Override
    public int insert(Bill bill) {
//        Item item = bill.getItem();
//        bill.setUseDate();
        return billDao.insert(bill);
    }

    /**
     * 修改
     *
     * @param bill 新纪录
     * @return 行数
     */
    @Override
    public int updateByBillId(Bill bill) {
        return billDao.updateByBillId(bill);
    }

    /**
     * 根据用户、状态、类型查找对应账单
     *
     * @param user      谁
     * @param state     订单状态
     * @param type      订单类型
     * @param beginDate 起日期
     * @param endDate   止日期
     * @return 订单集合
     */
    @Override
    public List<Bill> selectByUser(@Param("user") User user, @Param("billState") String state, @Param("billType") String type, @Param("beginDate") String beginDate, @Param("endDate") String endDate) {
        return billDao.selectByUser(user,state,type,beginDate,endDate);
    }

    /**
     * 根据Bill Id 查找bill
     *
     * @param id bill id
     * @return result
     */
    @Override
    public Bill selectByBillId(@Param("id") Integer id) {
        return billDao.selectByBillId(id);
    }
}
